package com.zlz.parent.basic.springboot.starter.oauth;

import com.zlz.parent.basic.springboot.starter.config.ModelConfig;
import com.zlz.parent.basic.springboot.starter.trace.LoginContext;
import com.zlz.parent.basic.springboot.starter.trace.TraceContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

@Slf4j
@Component
public class OauthFilter implements WebFilter, Ordered {

    private final ModelConfig modelConfig;

    public OauthFilter(ModelConfig modelConfig) {
        this.modelConfig = modelConfig;
    }

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        log.debug("OauthFilter: Start Auth");
        if(!modelConfig.isOauth()){
            log.debug("OauthFilter: Auth Not Open");
            return chain.filter(exchange);
        }
        log.debug("OauthFilter: Check Auth Token ...");
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return Integer.MIN_VALUE + 200;
    }
}

